<?php
class CV_Validate_Callback_Args extends CV_Validate_Abstract {
	protected $_args_before;
	protected $_args_after;
	protected $_callback;
	/**
	 * @param callback $callback
	 */
	public function __construct( $callback, $args_after = array(), $args_before = array() ){
		$this->_callback = $callback;
		if( is_array($args_after) ){
			$this->_args_after = array_values( $args_after );
		} elseif( $args_after === NULL ){
			$this->_args_after = array();
		} else {
			$this->_args_after = array( $args_after );
		}
		if( is_array($args_before) ){
			$this->_args_before = array_values( $args_before );
		} elseif( $args_before === NULL ){
			$this->_args_before = array();
		} else {
			$this->_args_before = array( $args_before );
		}
	}
	public function _isValid( $value ){
		$func_args = func_get_args();
		$args = array_merge(
			$this->_args_before,
			$func_args,
			$this->_args_after
		);
		if( call_user_func_array($this->_callback,$args) ){
			return true;
		}
		$this->_messages = array( "'%value%' does not validate against %callback%" );
		return false;
	}
}